//
//  TestCViewController.swift
//  Demo
//
//  Created by yuyang on 2021/11/25.
//

import Foundation
import UIKit
import YangRouter

extension TestCViewController: RouterRegisterProtocol {
    static func registerName() -> String {
        return "TestCViewController"
    }

    func pageWillPushAppearReceive(params: [String: Any]?, options: [String: Any]?) {
        print("")
    }

    func pageWillPopToAppearReceive(params: [String: Any]?, options: [String: Any]?) {
        print("")
    }
}

class TestCViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white

        let popToBButton = UIButton(type: .custom)
        popToBButton.backgroundColor = .black
        popToBButton.setTitle("popToBButton", for: .normal)
        view.addSubview(popToBButton)

        popToBButton.frame = CGRect(x: 10, y: 100, width: 200, height: 50)
        popToBButton.addTarget(self, action: #selector(popToB), for: .touchUpInside)

        let popToAButton = UIButton(type: .custom)
        popToAButton.backgroundColor = .orange
        popToAButton.setTitle("popToAButton", for: .normal)
        view.addSubview(popToAButton)

        popToAButton.frame = CGRect(x: 10, y: 200, width: 200, height: 50)
        popToAButton.addTarget(self, action: #selector(popToA), for: .touchUpInside)

        let popToRootButton = UIButton(type: .custom)
        popToRootButton.backgroundColor = .systemPink
        popToRootButton.setTitle("popToRootButton", for: .normal)
        
        view.addSubview(popToRootButton)

        popToRootButton.frame = CGRect(x: 10, y: 300, width: 200, height: 50)
        popToRootButton.addTarget(self, action: #selector(popToRoot), for: .touchUpInside)
    }

    @objc func popToB() {
        Router.popToPage("TestBViewController", params: ["from": "C", "to": "B"])
    }

    @objc func popToA() {
        Router.popToPage("TestAViewController", params: ["from": "C", "to": "A"], options: ["animated": false])
    }

    @objc func popToRoot() {
        Router.popToRootPage()
    }

}
